
var faceItem = cc.Class({
    name: 'faceItem',
    properties: {
       
        rankleaveimage:cc.String,
        rankName:cc.String,
        rankheadimage:cc.Integer,
        score:cc.String
      
    }
});
cc.Class({
    extends: cc.Component,

    properties: {
        items: {
            default: [],
            type:faceItem
        },//代码几个item格子 初始化
        itemPrefab: cc.Prefab,//预制节点 代表cell内容详情
        myheadSprite:cc.Node,
        mynameLabel:cc.Label,
        myscoreLabel:cc.Label,
        mysignSprite:cc.Node,
        ListAllScrollView:cc.Node,
        RankingAllView:cc.Node,
        myrankLabel:cc.Label,
        rankCloseBtn:cc.Button,
        wordScrolView:cc.Node
    },


    onLoad () {

     
    },

    init(){
      
        if(this.items.length>0){
            this.node.removeAllChildren();
        }

        FBInstant.getLeaderboardAsync('mouseFriend')
        .then((leaderboard) => {
            console.log('--leaderboard--');
            console.log(leaderboard)
            return leaderboard.getConnectedPlayerEntriesAsync(100, 0);
        })
        .then((entries) => {
            console.log('--entries--');

            for (var i = 0; i < entries.length; ++i) {
    
               var item = cc.instantiate(this.itemPrefab);
               this.node.addChild(item);
               let items=entries[i]
               let player=items.getPlayer()
               let obj={}
                obj["name"]=player.getName();
                obj["avatar"]=player.getPhoto();
                obj["score"]=items.getScore();
                obj["user_rank"]=i+1;
                console.log(i)
                item.getComponent('listPrefab').init(obj);

                var playerID = FBInstant.player.getID();
                if(playerID===player.getID()){
                    var _this=this
                    console.log("头像",obj["avatar"])
                    cc.loader.load({url: obj["avatar"], type: 'png'}, function(err,img){
        
                        var mylogo  = new cc.SpriteFrame(img); 
            
                        _this.myheadSprite.getComponent(cc.Sprite).spriteFrame = mylogo;
            
                        _this.myheadSprite.width=82
            
                        _this.myheadSprite.height=82
                        
                    });
                  this.mynameLabel.getComponent(cc.Label).string=player.getName()
                  this.myscoreLabel.getComponent(cc.Label).string=items.getScore();

                  if(i==0){

                    let _this = that
                    cc.loader.loadRes("leave_1", cc.SpriteFrame, function (err, spriteFrame) {
                 
                      _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
         
                    });
    
                }else if(i==1){
    
                    let _this = that
                    cc.loader.loadRes("leave_2", cc.SpriteFrame, function (err, spriteFrame) {
                 
                      _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
         
                    });
    
                }else if(i==2){
    
                    let _this = that
                    cc.loader.loadRes("leave_3", cc.SpriteFrame, function (err, spriteFrame) {
                 
                      _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
         
                    });
    
                }
                else{
                    
                      let _this = that
                       that.myrankLabel.node.active=true
                        that.myrankLabel.getComponent(cc.Label).string=i+1
                    cc.loader.loadRes("排名底框", cc.SpriteFrame, function (err, spriteFrame) {
                 
                      _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
         
                    });  
                
                }
            

                }

            }
        })

    },

    closeClick:function(){


        var changebig = cc.scaleTo(0.02,1.2);

        var finish = cc.callFunc(function(){
    
            var that=this
          var changesmail = cc.scaleTo(0.08,1.0);

          var smaillfinish=cc.callFunc(function(){

            that.ListAllScrollView.active=false

          })

          var seq2 = cc.sequence(changesmail,smaillfinish)
          this.rankCloseBtn.node.runAction(seq2)
       

       }, this);
    
       var seq = cc.sequence(changebig,finish)

       this.rankCloseBtn.node.runAction(seq)
        
    },

    start () {

    },

    worldListClick:function(){

    },

    friendListClick:function(){
     
        this.ListAllScrollView.active=false
        this.RankingAllView.active=true
        this.wordScrolView.getComponent("ListScrollView").init()
    
    }

    // update (dt) {},
});
